/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistance;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import local.Historique;
import local.Historique.Type;
import local.ctl.ctlHisto;
/**
 *
 * @author xarckane
 */
public class DaoHistorique {
   
     public static ArrayList<Historique> getAll() throws SQLException {
       ResultSet resultat = DatabaseConnector.getInstance().execQuery("select id,serv,date,type from histo order by date desc");
       ArrayList<Historique> histo = new ArrayList<Historique>();
       
       while (resultat.next()) {
           
                histo.add(ctlHisto.createHistorique(resultat.getString("serv"), resultat.getString("type"),resultat.getString("date"),resultat.getInt("id")));
                
            }
       
        return histo;
     }
     public static ArrayList<Historique> getAllByServ(String serv) throws SQLException {
       ResultSet resultat = DatabaseConnector.getInstance().execQuery("select id,serv,date,type from histo where serv=\""+serv+"\" order by date desc");
       ArrayList<Historique> histo = new ArrayList<Historique>();
     
       while (resultat.next()) {
           
                histo.add(ctlHisto.createHistorique(resultat.getString("serv"), resultat.getString("type"),resultat.getString("date"),resultat.getInt("id")));
                
            }
       
        return histo;
     }
     public static void clear() throws SQLException{
         DaoCpu.getInstance().clear();
         DaoMemory.getInstance().clear();
         DaoProcessus.getInstance().clear();
     }  
}
